﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using StudentMgmt.DBUtility;
using System.Data.SqlClient;

namespace StudentMgmt
{
    public partial class frmUserRegister : Form
    {
        public frmUserRegister()
        {
            InitializeComponent();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string usrName = this.tbUserName.Text.Trim();
            string psd = this.tbPassword.Text.Trim();
            string strsql = "insert into Usr(UserId,Psd) values(@UserId,@Psd)";
            SqlParameter[] parms = {
                new SqlParameter("@UserId",SqlDbType.Char),
                new SqlParameter("@Psd",SqlDbType.Char),
            };
            parms[0].Value = usrName;
            parms[1].Value = psd;
            try
            {
                SqlHelper.RunSQL(strsql, parms);
                MessageBox.Show("用户添加成功！");
                frmUserLogin frmLogin = new frmUserLogin();
                this.Hide();
                frmLogin.Show();
            }
            catch (Exception)
            {
                MessageBox.Show("用户添加失败！");
                throw;
            }
          
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
                this.Close();
                this.Dispose();
        }
    }
}
